Conditions | 1 |
Paths | 1 |
Total Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var inherits = require('../src/inherits.js'); |
||
26 | describe('successful tests', function() { |
||
27 | // test example from README.md |
||
28 | var SuperClass = function() { |
||
29 | this.someProperty = 42; |
||
30 | }; |
||
31 | |||
32 | SuperClass.prototype.retMsg = function(msg) { |
||
33 | return msg; |
||
34 | }; |
||
35 | |||
36 | SuperClass.prototype.getSomeProp = function() { |
||
37 | return this.someProperty; |
||
38 | }; |
||
39 | |||
40 | // a class we want to inherit from SuperClass |
||
41 | var SomeClass = function() { |
||
42 | SuperClass.call(this); |
||
43 | }; |
||
44 | |||
45 | inherits(SomeClass, SuperClass); |
||
46 | |||
47 | SomeClass.prototype.flop = function(msg) { |
||
48 | return this.retMsg(msg); |
||
49 | }; |
||
50 | |||
51 | var someClass_instance = new SomeClass(); |
||
52 | // end test example from README.md |
||
53 | |||
54 | it("should be able to access inherited properties", function() { |
||
55 | expect(someClass_instance.someProperty).toEqual(42); |
||
56 | }); |
||
57 | |||
58 | it("should be able to run inherited methods", function() { |
||
59 | expect(someClass_instance.retMsg('hi')).toEqual('hi'); |
||
60 | }); |
||
61 | |||
62 | it("should be able to run inherited methods by using the this keyword", function() { |
||
63 | expect(someClass_instance.flop('hi')).toEqual('hi'); |
||
64 | }); |
||
65 | |||
66 | it("should be instance of SomeClass", function() { |
||
67 | expect((someClass_instance instanceof SomeClass)).toEqual(true); |
||
68 | }); |
||
69 | |||
70 | it("should be instance of SuperClass", function() { |
||
71 | expect((someClass_instance instanceof SuperClass)).toEqual(true); |
||
72 | }); |
||
73 | |||
74 | it("should set SuperClass contructor", function() { |
||
75 | expect(someClass_instance.constructor.super_ === SuperClass).toEqual(true); |
||
76 | }); |
||
77 | |||
78 | it("should set contructor", function() { |
||
79 | expect(someClass_instance.constructor === SomeClass).toEqual(true); |
||
80 | }); |
||
81 | }); |
||
82 | }); |
||
83 |